using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Linq.Extensions;
using HCD.Const;
using HCD.Entities;
using HCD.Mdt.Dtos;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;

namespace HCD.Mdt
{
    /// <summary>
    /// MdtOrder 会诊干预医嘱(二期实现)
    /// </summary>
    [Route("api/[controller]/[action]"), ApiController]
    public class MdtOrderAppService : AsyncCrudAppService<MdtOrder,MdtOrderDto,long, MdtOrderGetAllInput, MdtOrderAddInput, MdtOrderEditInput, EntityDto<long>, EntityDto<long>>, IMdtOrderAppService
    {
        public MdtOrderAppService(IRepository<MdtOrder,long> repository)
        : base(repository)
        {
            LocalizationSourceName = EnterpriseConsts.LocalizationSourceName;
        }
        [HttpPost,ActionName("Add"), NonAction]
        public override async Task<MdtOrderDto> CreateAsync(MdtOrderAddInput input)
        {
            return await base.CreateAsync(input);
        }

        [HttpPut, ActionName("Edit"), NonAction]
        public override async Task<MdtOrderDto> UpdateAsync(MdtOrderEditInput input)
        {
            return await base.UpdateAsync(input);
        }

        [HttpDelete, ActionName("Delete"), NonAction]
        public override async Task DeleteAsync(EntityDto<long> input)
        {
            await base.DeleteAsync(input);
        }

        [HttpGet, ActionName("Get"), NonAction]
        public override async Task<MdtOrderDto> GetAsync(EntityDto<long> input)
        {
            return await base.GetAsync(input);
        }

        /// <summary>
        /// 获取Mdt医嘱(二期实现)
        /// </summary>
        /// <param name="input"></param>
        /// <returns>根据分页参数返回分页数据</returns>
        [HttpGet, ActionName("GetList")]
        public override async Task<PagedResultDto<MdtOrderDto>> GetAllAsync([FromQuery]MdtOrderGetAllInput input)
        {
            return await base.GetAllAsync(input);
        }
        protected override IQueryable<MdtOrder> CreateFilteredQuery(MdtOrderGetAllInput input)
        {
            return base.CreateFilteredQuery(input)
                .WhereIf(!string.IsNullOrWhiteSpace(input.PatientId), t => t.PatientId == input.PatientId);
        }

        /// <summary>
        /// 添加Mdt医嘱(二期实现)
        /// </summary>
        /// <param name="input"></param>
        /// <returns>保存如果成功，返回保存成功的MDT医嘱对象</returns>
        [HttpPut]
        public async Task<ListResultDto<MdtOrderDto>> SaveMdtOrders([FromBody]SaveMdtOrdersInput input)
        {
            return new ListResultDto<MdtOrderDto>();
        }
    }
}


